//
//  MyCommunityCell.m
//  LazyCat
//
//  Created by Abner on 16/10/11.
//  Copyright © 2016年 zhanshu. All rights reserved.
//

#import "MyCommunityCell.h"
#import "SFTagView.h"
#import "SFTag.h"
#import "SFTagButton.h"

@implementation MyCommunityCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = [UIColor whiteColor];
        [self creatProDetailTagCellUI];
    }
    return self;
}

-(void)creatProDetailTagCellUI
{
    self.leftLB = [[UILabel alloc]init];
    [self.contentView addSubview:self.leftLB];
    self.leftLB.font = FontSet(14);
    self.leftLB.textColor = SetColorRGBValue(0x878787, 1.0);
    
    self.tagView = [[SFTagView alloc] init];
    [self.contentView addSubview:self.tagView];
    // alignment 0 左对齐布局 1 右对齐布局
    self.tagView.alignment = 0;
    self.tagView.margin    = UIEdgeInsetsMake(9, 0, 9, 0); //整体
    self.tagView.insets    = 10; //左右间距
    self.tagView.lineSpace = 9; //上下间距
    
    self.bottomLine = [[UILabel alloc]init];
    [self.contentView addSubview:self.bottomLine];
}

-(void)setupMyCommunityCellData:(NSString *)name andTags:(NSArray *)tags
{
    self.leftLB.textColor = [UIColor blackColor];
    self.leftLB.font = FontSet(14);
    self.leftLB.text = name;
    CGFloat leftLBW = [self.leftLB.text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 14) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:FontSet(14)} context:nil].size.width;
    self.leftLB.frame = CGRectMake(8, 17.5, leftLBW, 14);
    
    CGFloat tagViewX = self.leftLB.right;
    if (tagViewX < 90-10) {
        tagViewX = 90-10;
    }
    SFTagView *tagView = [[SFTagView alloc] initWithFrame:CGRectMake(tagViewX, 0, ScreenWidth-tagViewX, 49)];
    self.tagView = tagView;
    [self.contentView addSubview:tagView];
    
    // alignment 0 左对齐布局 1 右对齐布局
    tagView.alignment = 0;
    tagView.margin    = UIEdgeInsetsMake(9, 0, 9, 0); //整体
    tagView.insets    = 10; //左右间距
    tagView.lineSpace = 9; //上下间距
    for (int j = 0; j<tags.count; j++) {
        SFTag *tag = [SFTag tagWithText:tags[j]];
        tag.textColor = SetColorRGBValue(0x333333, 1.0);
        tag.bgColor = [UIColor whiteColor];
        tag.target = self;
        tag.leftRightMargin = 12;
        tag.topBottomMargin = 4;
        tag.cornerRadius = 12;
        tag.borderWidth = 1;
        tag.font = FontSet(13);
        tag.borderColor = SetColorRGBValue(0xe0e0e0, 1.0);
        [tagView addTag:tag];
    }

    CGFloat lineY = tagView.bottom;
    
    if (lineY < 49) {
        CGFloat tagViewY = (49-tagView.height)/2;
        tagView.frame = CGRectMake(tagViewX, tagViewY, ScreenWidth-tagViewX, lineY);
        lineY = 49;
    }
    UILabel *line = [[UILabel alloc]initWithFrame:CGRectMake(10, lineY, ScreenWidth-10, 1)];
    self.bottomLine = line;
    line.backgroundColor = SetColor(235, 235, 242, 1.0);
    [self.contentView addSubview:line];
    
}


+(instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *indetifier = @"MyCommunityCellIdentifier";
    MyCommunityCell *cell = [tableView dequeueReusableCellWithIdentifier:indetifier];
    if (!cell) {
        cell = [[MyCommunityCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indetifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
